// Core type definitions for chat interface

export interface User {
  id: string
  name: string
  avatar: string
  role: 'agent' | 'client'
  email?: string
  phone?: string
  status: 'online' | 'offline' | 'away'
  lastSeen: Date
  createdAt: Date
  updatedAt: Date
}

export interface Message {
  id: string
  chatId: string
  senderId: string
  content: string
  timestamp: Date
  type: 'text' | 'image' | 'file'
  status: 'sending' | 'sent' | 'delivered' | 'read' | 'failed'
  metadata?: MessageMetadata
  replyTo?: string
  edited?: boolean
  editedAt?: Date
  createdAt: Date
  updatedAt: Date
}

export interface MessageMetadata {
  fileName?: string
  fileSize?: number
  fileType?: string
  imageWidth?: number
  imageHeight?: number
  duration?: number // for audio/video files
}

export interface Chat {
  id: string
  participants: User[]
  lastMessage: Message | null
  unreadCount: number
  status: 'active' | 'closed' | 'pending' | 'archived'
  title?: string
  description?: string
  tags: string[]
  priority: 'low' | 'normal' | 'high' | 'urgent'
  assignedAgent?: string
  createdAt: Date
  updatedAt: Date
  closedAt?: Date
}

export interface ClientData {
  id: string
  name: string
  avatar: string
  phone?: string
  email?: string
  company?: string
  position?: string
  location?: string
  timezone?: string
  language: string
  tags: Tag[]
  notes: string
  customFields: Record<string, any>
  history: ChatHistory[]
  preferences: ClientPreferences
  createdAt: Date
  updatedAt: Date
  lastContactAt?: Date
}

export interface ClientPreferences {
  preferredLanguage: string
  communicationChannel: 'chat' | 'email' | 'phone'
  availableHours: {
    start: string // HH:mm format
    end: string   // HH:mm format
    timezone: string
  }
  notifications: boolean
}

export interface ChatHistory {
  id: string
  date: Date
  summary: string
  messages: Message[]
}

export interface NavigationItem {
  id: string
  label: string
  icon: string
  path: string
}

export interface ActionButton {
  id: string
  label: string
  icon: string
  onClick: () => void
}

export interface ChatItem {
  id: string
  name: string
  avatar: string
  lastMessage: string
  timestamp: Date
  unreadCount: number
  status: 'online' | 'offline' | 'away'
}

export interface Tag {
  id: string
  name: string
  color: string
}

export interface UserPreferences {
  theme: 'light' | 'dark'
  language: string
  notifications: boolean
  soundEnabled: boolean
}

// Component Props Interfaces
export interface ChatAppProps {
  currentUser: User
  activeChat: Chat | null
}

export interface BigLeftProps {
  navigation: NavigationItem[]
  activeItem: string
  onNavigate: (item: string) => void
}

export interface TitleBarProps {
  chatTitle: string
  clientName: string
  onlineStatus: boolean
  actions: ActionButton[]
}

export interface TabsProps {
  chatList: ChatItem[]
  activeChat: string
  onChatSelect: (chatId: string) => void
}

export interface MessageHistoryProps {
  messages: Message[]
  loading: boolean
  onLoadMore: () => void
}

export interface MessageInputProps {
  onSendMessage: (content: string) => void
  placeholder: string
  disabled: boolean
}

export interface ClientInfoProps {
  client: ClientData | null
  tags: Tag[]
  onUpdateClient: (data: Partial<ClientData>) => void
}

export interface RightContentProps {
  titleBarProps: TitleBarProps
  rightBottomProps: RightBottomProps
}

export interface RightBottomProps {
  tabsProps: TabsProps
  chatMidProps: ChatMidProps
  clientInfoProps: ClientInfoProps
}

export interface ChatMidProps {
  messageHistoryProps: MessageHistoryProps
  messageInputProps: MessageInputProps
}

// State Management Interfaces
export interface AppState {
  user: UserState
  chats: ChatsState
  ui: UIState
  clients: ClientsState
}

export interface UserState {
  currentUser: User | null
  preferences: UserPreferences
}

export interface ChatsState {
  chatList: Chat[]
  activeChat: string | null
  messages: Record<string, Message[]>
  loading: boolean
}

export interface UIState {
  sidebarCollapsed: boolean
  activeTab: string
  clientInfoVisible: boolean
}

export interface ClientsState {
  currentClient: ClientData | null
  clientHistory: ChatHistory[]
}

// Re-export validation, factory, and serialization functions
export * from './validation'
export * from './factories'
export * from './serialization'